import React, { Component } from 'react';
import { Router, Route, IndexRoute } from 'react-router';
import App from 'common/containers/App.js';
import Error from 'common/containers/Error.js';
import 'common/containers/app.less';

/* 首页 */
import Main from '../main/Main.js';

/* 分类 */
import GoodsClassify from '../goodsClassify/GoodsClassify.js';
import GoodsSearch from '../goodsSearch/GoodsSearch.js';
import GoodsDetail from '../goodsDetail/GoodsDetail.js';

/* 发现 */
import Article from '../article/Article.js';

/* 购物车 */
import UserCart from '../userCart/UserCart.js';
import OrderPreview from '../orderPreview/OrderPreview.js';
import OrderPay from '../orderPay/OrderPay.js';

/* 我的 */
import UserInfo from '../userInfo/UserInfo.js';
import UserCash from '../userCash/UserCash.js';
import UserOrderList from '../userOrderList/UserOrderList.js';
import UserSetting from '../userSetting/UserSetting.js';
import UserAddress from '../userAddress/UserAddress.js';
import EditAddress from '../userAddress/EditAddress.js';

/* 售后 */
import UserOrderReturnApply from '../userOrderReturnApply/UserOrderReturnApply.js';

/* 注册登录 */
import Login from '../userAuth/Login.js';
import Register from '../userAuth/Register.js';

/**
 * 路由
 */
class RouteMap extends Component{

	onUpdate = () => {
		window.scrollTo(0,0);
	}

	render(){
		return(
			<Router history={this.props.history} onUpdate={this.onUpdate}>
				<Route path="/" component={App}>
					<IndexRoute component={Main} title="主页" />
					
					/* 首页 */
					<Route path="/main" component={Main}/>
					
					/* 分类 */
					<Route path="/goodsClassify" component={GoodsClassify}/>
					<Route path="/goodsSearch/:searchType" component={GoodsSearch}/>
					<Route path="/goodsSearch/:searchType/:searchKeyword" component={GoodsSearch}/>
					<Route path="/goodsDetail/:goodsId" component={GoodsDetail}/>
					
					/* 发现 */
					<Route path="/article" component={Article}/>
					
					/* 购物车 */
					<Route path="/userCart" component={UserCart}/>
					<Route path="/orderPreview/:cartIds" component={OrderPreview}/>
					<Route path="/orderPay/:orderId/:from" component={OrderPay}/>
					
					/* 我的 */
					<Route path="/userInfo" component={UserInfo}/>
					<Route path="/userCash" component={UserCash}/>
					<Route path="/userOrderList/:orderStatus" component={UserOrderList}/>
					<Route path="/userSetting" component={UserSetting}/>
					<Route path="/userAddress/:addressId" component={UserAddress}/>
					<Route path="/editAddress/:addressId" component={EditAddress}/>
					
					/* 售后 */
					<Route path="/userOrderReturnApply/:orderId/:returnType" component={UserOrderReturnApply}/>

					<Route path="/login" component={Login}/>
					<Route path="/register" component={Register}/>
					
					<Route path="*" component={Error}/>
				</Route>
			</Router>
		)
	}
}

export default RouteMap;